package net.lab1024.smartadmin.module.weapp.orderstype.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.weapp.orderstype.dao.WorkOrderTypeDao;
import net.lab1024.smartadmin.module.weapp.orderstype.domain.dto.WorkOrderTypeAddDTO;
import net.lab1024.smartadmin.module.weapp.orderstype.domain.dto.WorkOrderTypeUpdateDTO;
import net.lab1024.smartadmin.module.weapp.orderstype.domain.dto.WorkOrderTypeQueryDTO;
import net.lab1024.smartadmin.module.weapp.orderstype.domain.entity.WorkOrderTypeEntity;
import net.lab1024.smartadmin.module.weapp.orderstype.domain.vo.WorkOrderTypeVO;
import net.lab1024.smartadmin.module.weapp.orderstype.domain.vo.WorkOrderTypeExcelVO;
import net.lab1024.smartadmin.util.SmartPageUtil;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * [ 工单类型 ]
 *
 * @author wuqian
 * @version 1.0
 * @company 五千
 * @copyright (c)  五千Inc. All rights reserved.
 * @date 2021-03-12 09:13:38
 * @since JDK1.8
 */
@Service
public class WorkOrderTypeService {

    @Autowired
    private WorkOrderTypeDao workOrderTypeDao;

    /**
     * 根据id查询
     */
    public WorkOrderTypeEntity getById(Long id){
        return  workOrderTypeDao.selectById(id);
    }

    /**
     * 分页查询
     * @author wuqian
     * @date 2021-03-12 09:13:38
     */
    public ResponseDTO<PageResultDTO<WorkOrderTypeVO>> queryByPage(WorkOrderTypeQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<WorkOrderTypeVO> voList = workOrderTypeDao.queryByPage(page, queryDTO);
        PageResultDTO<WorkOrderTypeVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author wuqian
     * @date 2021-03-12 09:13:38
     */
    public ResponseDTO<String> add(WorkOrderTypeAddDTO addDTO) {
        WorkOrderTypeEntity entity = SmartBeanUtil.copy(addDTO, WorkOrderTypeEntity.class);
        entity.setCreateTime(new Date());
        entity.setUpdateTime(new Date());
        workOrderTypeDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author wuqian
     * @date 2021-03-12 09:13:38
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(WorkOrderTypeUpdateDTO updateDTO) {
        WorkOrderTypeEntity entity = SmartBeanUtil.copy(updateDTO, WorkOrderTypeEntity.class);
        workOrderTypeDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author wuqian
     * @date 2021-03-12 09:13:38
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        workOrderTypeDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author wuqian
     * @date 2021-03-12 09:13:38
     */
    public List<WorkOrderTypeExcelVO> queryAllExportData(WorkOrderTypeQueryDTO queryDTO) {
        return workOrderTypeDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author wuqian
     * @date 2021-03-12 09:13:38
     */
    public List<WorkOrderTypeExcelVO> queryBatchExportData(List<Long> idList) {
        return workOrderTypeDao.queryBatchExportData(idList);
    }
}
